package com.antler.smt.admin.service.impl;

import com.antler.smt.admin.mapper.MemberEntityMapper;
import com.antler.smt.admin.mapper.ProposalInfoMapper;
import com.antler.smt.entity.MemberEntity;
import com.antler.smt.request.base.BasePageReq;
import com.antler.smt.response.admin.GetProposalListResp;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.admin.ProposalService;
import com.antler.smt.utils.LogUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 意见反馈接口
 *
 * @author zhangyi
 * @date 2018/3/21 14:12
 */
@Service
public class ProposalServiceImpl implements ProposalService {

  /**
   * 日志
   */
  private static Logger log = LogUtil.get();


  @Autowired
  private ProposalInfoMapper proposalInfoMapper;

  @Autowired
  private MemberEntityMapper memberEntityMapper;

  /**
   * 获取意见与建议的列表
   *
   * @param request 请求实体
   * @return
   */
  @Override
  public Result<Page<GetProposalListResp>> listProposal(BasePageReq request) {
    PageHelper.startPage(request.getPageCurrent(), request.getPageSize());
    Page<GetProposalListResp> listProposal = proposalInfoMapper.listProposal();

    for(int i = 0; i < listProposal.size(); i++){
      Long memberId = listProposal.get(i).getMemberId();
      MemberEntity memberEntity = memberEntityMapper.selectByPrimaryKey(memberId);
      if(memberEntity != null){
          if(!memberEntity.getEmail().equals("null")){
            listProposal.get(i).setEmail(memberEntity.getEmail());
          }else if(!memberEntity.getMobile().equals("null")){
            listProposal.get(i).setMoblie(memberEntity.getMobile());
          }
      }
    }

    PageInfo<GetProposalListResp> proposalListPageInfo = null;
    if (listProposal != null) {
      proposalListPageInfo = new PageInfo(listProposal);
    }
    Result result = new Result(proposalListPageInfo);
    return result;
  }
}
